//
//  HomeshopCell.m
//  pmmSS
//
//  Created by Mac book on 2017/9/7.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "HomeshopCell.h"
#import "HomeCollectionCell.h"
#import "Commodity_Detail_ViewController.h"

@interface HomeshopCell()<UICollectionViewDelegate,UICollectionViewDataSource>

@property (strong,nonatomic) UICollectionViewFlowLayout *layout;
@property (strong,nonatomic) UICollectionView *collectionView;

@end

@implementation HomeshopCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {


        [self initSubViews];

    }
    return self;
}


-(void)initSubViews{



}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 4;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{



    HomeCollectionCell *detailCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeCollectionCell" forIndexPath:indexPath];

     detailCell.backgroundColor = [UIColor whiteColor];



    return detailCell;


}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{


    NSNumber *shopId= [NSNumber numberWithUnsignedLong:indexPath.item];

    NSString*_shopIdstr = [NSString stringWithFormat:@"%@",shopId];

    [self.delegate clickCollectionItem:[NSString stringWithFormat:@"%@", _shopIdstr]];
}

- (void)layoutSubviews {

    [super layoutSubviews];
    NSLog(@"self.frame.size.width-2/2is %f", self.frame.size.width-2/2);

    self.layout = [[UICollectionViewFlowLayout alloc] init];
    self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //确定item的大小
    _layout.itemSize = CGSizeMake((self.frame.size.width-1)/2, autoScaleH(90));

   //确定横向间距
    self.layout.minimumLineSpacing = 1;

   //确定纵向间距
    self.layout.minimumInteritemSpacing = 1;

    //确定距离上左下右的距离
    self.layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);


    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0,GET_FRAME_WIDTH(self),GET_FRAME_HEIGHT(self)) collectionViewLayout:self.layout];
    self.collectionView.backgroundColor = [UIColor lightGrayColor];


    //禁止滑动
    self.collectionView.scrollEnabled = NO;

    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;

    self.collectionView.showsVerticalScrollIndicator = NO;

    [self.contentView addSubview:self.collectionView];


    [self.collectionView registerClass:[HomeCollectionCell class] forCellWithReuseIdentifier:@"HomeCollectionCell"];

}


@end
